package com.shrct.businessprocess.project.impl;

import com.shrct.businessprocess.organization.RCEmployee;
import com.shrct.businessprocess.project.RCProjectSaleAssignment;
import com.shrct.businessprocess.project.RCProjectSaleAssignmentCriteria;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.hibernate.Query;

public class RCProjectSaleAssignmentCriteriaImpl extends HQLBasedPagedQueryCriteria<RCProjectSaleAssignment> implements RCProjectSaleAssignmentCriteria {
  private String year;
  
  public String getYear() {
    return this.year;
  }
  
  public RCProjectSaleAssignmentCriteria setYear(final String year) {
    this.year = year;
    return this;			
    
  }
  
  private RCEmployee sales;
  
  public RCEmployee getSales() {
    return this.sales;
  }
  
  public RCProjectSaleAssignmentCriteria setSales(final RCEmployee sales) {
    this.sales = sales;
    return this;			
    
  }
  
  private Boolean isEarlyBuild;
  
  public Boolean getIsEarlyBuild() {
    return this.isEarlyBuild;
  }
  
  public RCProjectSaleAssignmentCriteria setIsEarlyBuild(final Boolean isEarlyBuild) {
    this.isEarlyBuild = isEarlyBuild;
    return this;			
    
  }
  
  private String _year;
  
  public String get_year() {
    return this._year;
  }
  
  public RCProjectSaleAssignmentCriteria set_year(final String _year) {
    this._year = _year;
    return this;			
    
  }
  
  public void postInitialize() {
    boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(this.year);
    boolean _not = (!_isNullOrEmpty);
    if (_not) {
      String _plus = (this.year + "%");
      this._year = _plus;
    }
  }
  
  protected String buildHQLFrom() {
    return " from com.shrct.businessprocess.project.impl.RCProjectSaleAssignmentImpl this  left join  this.project.stat as stat ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(get_year()) ){
    	hql += " and (this.project.code  LIKE :_year)" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSales()) ){
    	hql += " and ((this.employee) = (:sales))" ;
    }
    	hql += " and ((this.project.passed) = (true))" ;
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsEarlyBuild()) ){
    	hql += " and ((this.project.earlyBuildInfo.isEarlyBuild) = (:isEarlyBuild))" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    addOrder("this.project.code",edu.fudan.mylang.pf.query.OrderItem.ASC);
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSales())){
    	query.setParameter("sales",getSales()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsEarlyBuild())){
    	query.setParameter("isEarlyBuild",getIsEarlyBuild()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(get_year())){
    	query.setParameter("_year",get_year()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return false;
  }
  
  public RCProjectSaleAssignmentCriteriaImpl() {
    initOrderBys();
  }
}
